Conversation
|
Thank you for opening this pull request! Reviewer note: cargo-semver-checks reported the current version number is not SemVer-compatible with the changes in this pull request (compared against the base branch). Details |
| #[deprecated( | ||
| since = "56.0.0", | ||
| note = "Please use `ComposedNamedPhysicalExtensionCodec`" | ||
| )] |
There was a problem hiding this comment.
Still not sure if it's worth to deprecate this one, FWIW both could live together.
| /// A PhysicalExtensionCodec that tries one of multiple inner codecs until one works. | ||
| /// The name of the codec that successfully encoded an [`ExecutionPlan`] is stored in the | ||
| /// encoded payload, and the codec with that exact name will be used for decoding. | ||
| #[derive(Default, Debug)] | ||
| pub struct ComposedNamedPhysicalExtensionCodec { | ||
| codecs: HashMap<Cow<'static, str>, Arc<dyn PhysicalExtensionCodec>>, | ||
| } |
There was a problem hiding this comment.
cc @milenkovicm, do you have any opinions about this?
There was a problem hiding this comment.
Could string make encoded message too big? Could you consider u8 keys
There was a problem hiding this comment.
Or even u16 or u32, as the keys
There was a problem hiding this comment.
If you consider sorted keys, you can implement codec priority as well. I know strings are more flexible than numbers but they won't remove synchronisation between orgs and they can be abused with key size
There was a problem hiding this comment.
I don't think abuse is a worry here, as the provided String name is not un-sanitized input coming from the outside. Of course a developer can go crazy and provide an unreasonably long string here out of malice, but they can do that as well while serializing their custom plans, so it's not really a new risk.
My guess is that adding ~30 bytes worth of a string should not bee too bad, because this only affects custom nodes provided by users, not each node in the plan, so it should be negligible.
If you consider sorted keys, you can implement codec priority as well
🤔 this sounds interesting, but I don't understand it very well. How would this priority mechanism work?
There was a problem hiding this comment.
coming from perspective of building binary protocols having string as a key does not look like best practice. you're right string keys might not be much but it does not mean it should be used, there is no real benefit of it compared to integers, apart from delaying decision on codec composition.
if you have sortable keys, you can add priority in which encoders should be executed, its a user decision, this makes encoding deterministic.
There was a problem hiding this comment.
🤔 But determinism is not really the problem to solve here. For example:
Machine 1: [CodecA, CodecB, CodecC] <- pre-rollout
Machine 2: [CodecA, CodecD, CodecB, CodecC] <-post-rollout
Here, encoding is deterministic: codecs will always be attempted in the same order, but decoding still fails. It will deterministically fail every time until Machine 1 fully rolls out.
Maybe I'm missing how determinism can solve this issue?
There was a problem hiding this comment.
I was talking about something slightly different.
Lets say you have event E which had 3 versions (lets say backward compatible), lets say that you have two codecs C1 and C2 each of which can encode E, C1 can encode in version 2, C2 can encode version 3. if you do not have codec priority, just by naming things, C1 could encode E even when C2 has latest version, so your encoding process will remove peace of information unnecessary.
so someone should make decision who to go first, and they should be able to say which one has precedence
There was a problem hiding this comment.
👍 thanks for the explanation, I understand it now.
It sounds like just replacing the HashMap with a BtreeMap should be enough for addressing this. The BtreeMap will give this deterministic order in which codecs are tried for encoding.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #24826 +/- ##
==========================================
- Coverage 81.58% 81.56% -0.03%
==========================================
Files 1123 1123
Lines 406610 406707 +97
Branches 406610 406707 +97
==========================================
- Hits 331719 331715 -4
- Misses 55453 55554 +101
Partials 19438 19438 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Closing in favor of #24631 |
Which issue does this PR close?
Rationale for this change
The
ComposedPhysicalExtensionCodecallowed to register multiple codecs, which are tried one by one until one works. When one works, the index of the list that occupies the codec that works is stored in the encoded payload for later decoding:The issue with this setup is that codecs can only be added to the end of the list, otherwise, while decoding, the index will be messed up and decoding will fail. In a setup with progressive rollouts this is very likely to happen.
While working in a small team, it's reasonable to expect developers to behave and just add new codecs at the end, however, when there are many teams contributing to the same list, with a non-centralized piece of code that has mutable access to it, it's easy to be in the situation where new codecs are not added at the end.
What changes are included in this PR?
Introduces a new
ComposedNamedPhysicalExtensionCodecthat identifies encoded payloads by codec name instead of by index in a list. This way, registration order does not matter, and this problem becomes irrepresentable:What is the testing strategy for this PR?
TODO
Are there any user-facing changes?
New
ComposedNamedPhysicalExtensionCodecis added to the public API, while keeping the previousComposedPhysicalExtensionCodecstill available.